package org.springblade.modules.repair.utils;

import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import cn.hutool.http.Method;
import org.springblade.core.tool.utils.Func;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;

public class HttpHeadUtil {
    public static String getDecodedWatermark(String url) throws UnsupportedEncodingException {
		HttpResponse executeResponse = HttpRequest.get(url).method(Method.HEAD).execute();
		// 当没有水印时，返回空字符串
		if (Func.isBlank(executeResponse.header("x-oss-meta-watermark"))) {
			return "";
		}
		String watermark = executeResponse.header("x-oss-meta-watermark");
		return URLDecoder.decode(watermark, String.valueOf(StandardCharsets.UTF_8));
    }
}
